// 引入 applyMiddleware 使用中间件
import { createStore, applyMiddleware } from "redux";
import reducer from "./reducer";
import mySagas from "./sagas"

// 引入 redux-thunk 库
// import thunk from "redux-thunk"

// 引入 saga
import createSagaMiddleware from "redux-saga"
// 创建 saga 中间件
const sagaMiddleware = createSagaMiddleware()

/* 
  1.store 必须是唯一的
  2.只有 store 能改变自己的内容，Reducer不能改变
  3.Reducer 必须是纯函数
*/
// const store = createStore(reducer);

// thunk
// const store = createStore(reducer, applyMiddleware(thunk));

// saga
const store = createStore(reducer, applyMiddleware(sagaMiddleware));

// 运行 saga
sagaMiddleware.run(mySagas)

export default store;
